﻿using System.Text;

namespace Jayden.Dll.Core.Logging
{
	public abstract class Handler
	{
		private Encoding m_Encoding = Encoding.ASCII;
		private Filter m_Filter;
		private Level m_Level;
		private Formatter m_Formatter;

		public abstract void Close();
		public abstract void Flush();

		public Encoding Encoding { get { return m_Encoding; } set { m_Encoding = value; } }
		public Filter Filter { get { return m_Filter; } set { m_Filter = value; } }
		public Formatter Formatter { get { return m_Formatter; } set { m_Formatter = value; } }
		public Level Level { get { return m_Level; } set { m_Level = value; } }

		public bool IsLoggable(LogRecord record)
		{
			if (m_Level == null)
				return true;
			if (record.Level == null)
				return false;
			return m_Level.Value <= record.Level.Value && (Filter == null || Filter.IsLoggable(record));
		}

		public abstract void Publish(LogRecord record);


	}
}
